package com.xuwangcheng.timer;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class TimerTest {
	public static void main(String[] args) {
		Timer t = new Timer();
		//当前一次执行完成之后才开始计算间隔时间
		t.schedule(new SimpleTimeTask(), 2000, 2000);
		//前一次开始执行时计算间隔时间
		//t.scheduleAtFixedRate(new SimpleTimeTask(), 2000, 2000);
	}
}

class SimpleTimeTask extends TimerTask {

	@Override
	public void run() {
		// TODO Auto-generated method stub
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
		System.out.println("当前时间为：" + sdf.format(new Date()));
	}
	
}
